package com.atguigu.a_operator;

public class Demo3 {
    public static void main(String[] args) {
        int num = 10;

        //单独使用
        //num++;
        ++num;

        System.out.println("num = " + num);
        System.out.println("--------------------------");

        int x = 20;

        //int y = x++; //先参与运算,再自增
        int y = ++x; //先自增,再参与运算

        System.out.println("x = " + x);//21
        System.out.println("y = " + y);//21
        System.out.println("--------------------------");
        //输出语句会先计算括号内的结果 -> 算++在参与运算
        System.out.println(x++);//21
        System.out.println(x);//22

        System.out.println(++x);//23
        System.out.println("--------------------------");
        //以下代码有点蠢
        x = ++x;//24 -> x++/++x;
        System.out.println("x = " + x);//24
        System.out.println("--------------------------");
        //一句代码中,对变量的=号赋值之后,就不能有其他赋值操作了
        int z = x++ + ++x;//24 + 26
        System.out.println("x = " + x);//26


        System.out.println("z = " + z);//50
        System.out.println("--------------------");
        //以下代码蠢过头 -> 禁止这样写
        x = x++;
        System.out.println("--------------------");
        int i = 1;
        int j = i++ + ++i * i++; //1 + 3 * 3
        System.out.println("j = " + j);//10
        System.out.println("i = " + i);
    }
}
